let mongoose = require('mongoose');
let autoIncrement = require("mongoose-auto-increment");
let Schema = mongoose.Schema;

let dbConfig = require('../../../config/mongo.json');
let MongoDbAddress;
if (dbConfig.mongo.user !== null && dbConfig.mongo.password !== null) {
    MongoDbAddress = 'mongodb://' + dbConfig.mongo.user + ':' + dbConfig.mongo.password + '@' + dbConfig.mongo.host + ':' + dbConfig.mongo.port + '/' + dbConfig.mongo.database;
} else {
    MongoDbAddress = 'mongodb://' + dbConfig.mongo.host + ':' + dbConfig.mongo.port + '/' + dbConfig.mongo.database;
}

let options = {
    auth: { authdb: dbConfig.mongo.database },
    db: { native_parser: true },
    server: { poolSize: 5 },
    user: dbConfig.mongo.user,
    pass: dbConfig.mongo.password
};
let db = mongoose.createConnection(MongoDbAddress, options);
autoIncrement.initialize(db);

// 帐号
let accountSchema = new Schema({
    uid: { type: Number, default: 0, unique: true },
    account: { type: String, default: "" },
    password: { type: String, default: "" },
    phoneAccount: { type: String, default: "" },
    wxAccount: { type: String, default: "" },
    registerInfo: { type: String, default: "" }
});
db.model('account', accountSchema);
exports.accountModel = db.model('account');

// 管理员
let adminSchema = new Schema({
    account: { type: String, default: "" },
    password: { type: String, default: "" },
    permission: { type: Number, default: 0 },
    nickname: { type: String, default: "" },
    createTime: { type: Number, default: 0 }
});

adminSchema.plugin(autoIncrement.plugin, {
    model: 'admin',
    field: 'uid',
    startAt: 100000,
    incrementBy: 1
});

db.model('admin', adminSchema);
exports.adminModel = db.model('admin');


// 团队数据统计
let teamDataSchema = new Schema({
    unionID: { type: Number, default: 0 },
    userCount: { type: Number, default: 0 },
    drawCount: { type: Number, default: 0 },
    drawTotalCount: { type: Number, default: 0 },
    diamondCount: { type: Number, default: 0 },
    dateTime: { type: String, default: "" },
    createTime: { type: String, default: "" }
});

db.model('teamData', teamDataSchema);
exports.teamDataModel = db.model('teamData');


// 玩家数据统计
let userScoreDataSchema = new Schema({
    unionID: { type: Number, default: 0 },
    uid: { type: Number, default: 0 },
    count: { type: Number, default: 0 },
    score: { type: Number, default: 0 },
    dateTime: { type: String, default: "" },
    dayTime: { type: Number, default: "" },
    createTime: { type: String, default: "" }
});

db.model('userScoreData', userScoreDataSchema);
exports.userScoreDataModel = db.model('userScoreData');


// 赠送记录
let adminGrantRecordSchema = new Schema({
    uid: { type: String, default: "" },
    nickname: { type: String, default: "" },
    gainUid: { type: String, default: "" },
    type: { type: String, default: "" },
    count: { type: String, default: "" },
    createTime: { type: Number, default: 0 }
});
db.model('adminGrantRecord', adminGrantRecordSchema);
exports.adminGrantRecordModel = db.model('adminGrantRecord');

// 用户
let userSchema = new Schema({

    deviceID: { type: String, default: "" },
    minScore: { type: Number, default: 0 },
    maxScore: { type: Number, default: 0 },
    beginTime: { type: Number, default: 0 }, //开始投放时间
    endTime: { type: Number, default: 24 }, //结束投放时间
    winScore: { type: Number, default: 0 }, //最大赢分
    loseScore: { type: Number, default: 0 }, //最大输分
    isTest: { type: Boolean, default: false }, //是否有调试权限
    isRobot: { type: Boolean, default: false }, //是否是机器人
    winType: { type: Number, default: 0 }, //控制类型
    winRate: { type: Number, default: 0 }, //输赢比例
    unionID: { type: Number, default: 0 }, //机器人联盟ID
    robotTest: { type: Number, default: 0 }, //机器人测试
    robotType: { type: Number, default: 0 }, //机器人类型0：相互模拟 1：被动陪打 2：主动陪打
    gameType: { type: Number, default: 0 }, //投放游戏类型 0全部
    isReback: { type: Boolean, default: false }, //是否回收中
    userType: { type: Number, default: 0 }, //用户类型 0:普通用户 1：黑名单 2：白名单
    account: { type: String, default: "" }, //用户绑定的账号
    // 基础信息
    uid: { type: String, default: "" }, // 用户唯一ID
    nickname: { type: String, default: "" }, // 昵称
    wechatCode: { type: String, default: "" }, // 微信
    qqCode: { type: String, default: "" }, // qq
    avatar: { type: String, default: "" }, // 头像
    avatar64: { type: String, default: "" }, // base64头像
    avatarFrame: { type: String, default: "" }, // 头像框
    sex: { type: Number, default: 0 }, // 性别
    // 联盟信息
    unionInfo: [{
        userType: { type: Number, default: 0, }, //1 黑 2 白
        sortType: { type: Number, default: 0, },
        inviteID: { type: Number, default: 0 }, // 我的邀请ID
        unionID: { type: Number, default: 0 }, // 联盟ID
        spreaderID: { type: String, default: "" }, // 推广员ID
        score: { type: Number, default: 0 }, // 积分数量
        targetScore: { type: Number, default: 0 }, // 目标分数
        floatScore: { type: Number, default: 0 }, // 浮动分数
        safeScore: { type: Number, default: 0 }, // 保险柜积分
        saveScore: { type: Number, default: 0 }, // 储蓄分数
        partner: { type: Boolean, default: false }, // 是否是合伙人
        manager: { type: Boolean, default: false }, // 是否是管理人员
        showFixScore: { type: Boolean, default: false }, // 是否显示保底明细
        fixScoreRate: { type: Number, default: 0 }, // 保底返利
        ticketRate: { type: Number, default: 0 }, // 返利比例
        rebateRate: { type: Number, default: 0 }, // 返利比例
        limitScore: { type: Number, default: 0 }, // 警戒线
        todayDraw: { type: Number, default: 0 }, // 今日总局数
        yesterdayDraw: { type: Number, default: 0 }, // 昨日总局数
        totalDraw: { type: Number, default: 0 }, // 总局数
        weekDraw: { type: Number, default: 0 }, // 每周局数
        memberTodayDraw: { type: Number, default: 0 }, // 成员今日总局数
        memberYesterdayDraw: { type: Number, default: 0 }, // 成员昨日总局数
        todayBigWinDraw: { type: Number, default: 0 }, // 今日大赢家局数
        yesterdayBigWinDraw: { type: Number, default: 0 }, // 昨日大赢家局数
        memberTodayBigWinDraw: { type: Number, default: 0 }, // 成员今日大赢家局数
        memberYesterdayBigWinDraw: { type: Number, default: 0 }, // 成员昨日大赢家局数
        todayProvideRebate: { type: Number, default: 0 }, // 今日贡献返利
        yesterdayProvideRebate: { type: Number, default: 0 }, // 昨日贡献返利
        todayRebate: { type: Number, default: 0 }, // 今日返利
        yesterdayRebate: { type: Number, default: 0 }, // 昨日返利
        totalRebate: { type: Number, default: 0 }, // 总返利
        todayWin: { type: Number, default: 0 }, // 今日赢分
        yesterdayWin: { type: Number, default: 0 }, // 昨日赢分
        prohibitGame: { type: Boolean, default: false }, // 禁止游戏
        joinTime: { type: Number, default: 0 }, // 加入时间
    }],
    gold: { type: Number, default: 0 }, // 金币(房卡)
    goldScore: { type: Number, default: 0 }, // 金币(金币场)
    emailArr: { type: String, default: "" }, // 邮件
    inviteMsg: [{
        uid: { type: String, default: "" }, // 邀请人ID
        nickname: { type: String, default: "" }, // 邀请人名字
        unionID: { type: Number, default: 0 }, // 俱乐部ID
        partner: { type: Boolean, default: false }, // 是否标记为合伙人
        unionName: { type: String, default: "" } // 俱乐部名字
    }],
    mobilePhone: { type: String, default: "" }, // 绑定的手机
    realName: { type: String, default: "" }, // 实名认证信息
    isAgent: { type: Boolean, default: true }, // 是否是代理
    isBind: { type: Boolean, default: false }, //是否绑定
    roomID: { type: String, default: "" }, // 房间ID
    frontendId: { type: String, default: "" }, // 前端服务器ID
    syncLock: { type: Number, default: 0 }, // 同步锁
    address: { type: String, default: "" }, // 地理位置经纬度
    location: { type: String, default: "" }, // 地理位置信息，国家省市街道
    isBlockedAccount: { type: Number, default: 0 }, // 是否冻结帐号
    lastLoginIP: { type: String, default: "" }, // 最后登录IP
    lastLoginTime: { type: Number, default: 0 }, // 最后登录时间
    createTime: { type: Number, default: 0 } // 创建时间
});

userSchema.index({ uid: 1 });
db.model('user', userSchema);
exports.userModel = db.model('user');


// 玩家分数汇总
let userScoreSchema = new Schema({

    unionID: { type: Number, default: 0 }, // 联盟ID
    uid: { type: Number, default: 0 }, // ID
    nickname: { type: String, default: "" }, // 名字
    avatar: { type: String, default: "" }, // 头像
    score: { type: Number, default: 0 }, // 输赢分数
    userScore: { type: Number, default: 0 }, // 玩家当前分数
    saveScore: { type: Number, default: 0 }, // 保险柜分数
    dayTime: { type: Number, default: 0 }, // 分数时间
    createTime: { type: Number, default: 0 }, // 创建时间 
});

userSchema.index({ dayTime: -1, uid: 1, unionID: 1 });

db.model('userScore', userScoreSchema);
exports.userScoreModel = db.model('userScore');


// 通用参数
let configSchema = new Schema({
    key: { type: String, default: "" },
    value: { type: String, default: "" },
    describe: { type: String, default: "" }
});
db.model('config', configSchema);
exports.configModel = db.model('config');

// 唯一ID记录
let uniqueIDSchema = new Schema({
    key: { type: Number, default: 1 },
    unionInviteID: { type: Number, default: 23467335 }
});
db.model('uniqueID', uniqueIDSchema);
exports.uniqueIDModel = db.model('uniqueID');

// 联盟
let unionSchema = new Schema({

    unionSkinId: { type: String, default: "" }, // 联盟皮肤ID
    unionInviteID: { type: Number, default: 0 },
    unionGameType: { type: Number, default: 0 },
    unionType: { type: Number, default: 0 },
    ownerUid: { type: String, default: "" }, // 盟主Uid
    ownerNickname: { type: String, default: "" }, // 盟主昵称
    ownerAvatar: { type: String, default: "" }, // 盟主头像
    unionName: { type: String, default: "" }, // 联盟名字
    ownerPhone: { type: String, default: "" }, // 联系人电话
    ownerWeChat: { type: String, default: "" }, //联系人微信号
    curMember: { type: Number, default: 0 }, // 当前成员数量
    onlineMember: { type: Number, default: 0 }, // 在线成员数量
    roomRuleList: [{
        createTime: { type: String, default: 0 },
        gameType: { type: Number, default: 0 }, // 游戏类型
        ruleName: { type: String, default: "" }, // 房间名字
        gameRule: { type: String, default: "" }, // 游戏规则
    }],
    allowCreateRoom: { type: Boolean, default: true }, // 是否允许创建房间
    maxRoomCount: { type: Number, default: 30 }, // 最大房间数量
    notice: { type: String, default: "" }, // 公告
    noticeSwitch: { type: Boolean, default: false }, // 公告开关
    allowMerge: { type: Boolean, default: false }, // 允许合并
    opening: { type: Boolean, default: true }, // 是否正在营业
    emptyTable: { type: Boolean, default: false }, // 禁止空桌
    isInvite: { type: Boolean, default: false }, // 是否允许邀请
    fullTableLimit: { type: Number, default: 0 }, // 满桌显示上限
    joinRequestList: [{ // 加入请求列表
        inviteID: { type: String, default: "" },
        spreaderID: { type: String, default: "" },
        uid: { type: String, default: "" }, // 请求者id
        nickname: { type: String, default: "" }, // 昵称
        avatar: { type: String, default: "" }, // 头像
        createTime: { type: Number, default: 0 } // 请求时间
    }],
    exitRequestList: [{ // 退出请求列表
        uid: { type: String, default: "" }, // 请求者id
        nickname: { type: String, default: "" }, // 昵称
        avatar: { type: String, default: "" }, // 头像
        createTime: { type: Number, default: 0 } // 请求时间
    }],
    showRank: { type: Boolean, default: false }, // 是否允许显示排行榜
    showSingleRank: { type: Boolean, default: false }, // 是否允许显示单局排行榜
    showUnionActive: { type: Boolean, default: false }, // 是否允许显示联盟活动
    forbidInvite: { type: Boolean, default: false }, // 是否禁止邀请
    forbidGive: { type: Boolean, default: false }, // 是否禁止赠送分数
    hongBaoInfo: {},
    hongBaoScoreList: {}, // 红包金额列表
    resultLotteryInfo: {},
    hongBaoUidList: {}, // 红包领取用户列表
    createTime: { type: Number, default: 0 }, // 创建时间
    serverScore: { type: Number, default: 0 }, // 服务费(百分比)
    tableSort: { type: Number, default: 0 }, //联盟牌桌排序
    isTeamData: { type: Boolean, default: false }, // 团队统计页面
    isUserData: { type: Boolean, default: true }, //个人统计页面
    isScoreData: { type: Boolean, default: false }, // 积分明细
    gameLimited: [], //游戏限制
    isMain: { type: Number, default: 0 }, //是否推荐联盟
    isDel: { type: Boolean, default: false }, // 联盟是否删除
    pumpWaterPattern: { type: Boolean, default: false }, // 抽水模式(false为单向 ture为双向)
    tableColor: { type: Number, default: 0 }, // 联盟牌桌颜色
    unionBg: { type: Number, default: 0 }, // 联盟牌背景颜色
    tableStyle: { type: Number, default: 0 }, // 联盟牌桌样式
    disApplyCount: { type: Number, default: 0 }, //解散申请次数
    inviteLimit: { type: Boolean, default: false }, //用户主动加入
    joinVerify: { type: Boolean, default: false }, //进圈审核
    propsLimit: { type: Boolean, default: false }, //禁用道具
    tableHideCount: { type: Number, default: 0 }, // 默认: 0 - 不隐藏 ，1-全部隐藏，2-隐藏1 / 2, 3-隐藏1 / 3
    unReadyKick: { type: Number, default: 0 },
    groupLimit: { type: Boolean, default: false }, //同组禁入 
    dismissType: { type: Number, default: 0 }, //解散类型

});
unionSchema.plugin(autoIncrement.plugin, { model: 'union', field: 'unionID', startAt: 30463, incrementBy: 1 });
unionSchema.index({ unionID: 1 });
db.model('union', unionSchema);
exports.unionModel = db.model('union');

// 保险柜操作记录
let safeBoxRecordSchema = new Schema({
    uid: { type: String, default: "" }, // 操作者ID
});
safeBoxRecordSchema.plugin(autoIncrement.plugin, {
    model: 'safeBoxRecord',
    field: 'index',
    startAt: 10000001,
    incrementBy: 1
});
db.model('safeBoxRecord', safeBoxRecordSchema);
exports.safeBoxRecordModel = db.model('safeBoxRecord');

// 改分记录
let scoreModifyRecordSchema = new Schema({
    uid: { type: String, default: "" }, // 改成ID

});
scoreModifyRecordSchema.plugin(autoIncrement.plugin, {
    model: 'scoreModifyRecord',
    field: 'index',
    startAt: 1000001,
    incrementBy: 1
});
db.model('scoreModifyRecord', scoreModifyRecordSchema);
exports.scoreModifyRecordModel = db.model('scoreModifyRecord');

// 赠送积分记录
let scoreGiveRecordSchema = new Schema({
    uid: { type: String, default: "" }, // 改成ID
    nickname: { type: String, default: "" }, // 改分昵称
    gainUid: { type: String, default: "" }, // 被改分者ID
    gainNickname: { type: String, default: "" }, // 被改分者昵称
    unionID: { type: Number, default: 0 }, // 联盟ID
    count: { type: Number, default: 0 }, // 数量
    createTime: { type: Number, default: 0 } // 时间
});
scoreGiveRecordSchema.plugin(autoIncrement.plugin, {
    model: 'scoreGiveRecord',
    field: 'index',
    startAt: 1000001,
    incrementBy: 1
});
db.model('scoreGiveRecord', scoreGiveRecordSchema);
exports.scoreGiveRecordModel = db.model('scoreGiveRecord');


// 玩家游戏记录
let userGameRecordSchema = new Schema({
    roomID: { type: String, default: "" },
    unionID: { type: Number, default: 0 },
    creatorUid: { type: String, default: "" },
    gameType: { type: Number, default: 0 },
    userList: [{
        uid: { type: String, default: "" },
        nickname: { type: String, default: "" },
        avatar: { type: String, default: "" },
        score: { type: Number, default: 0 },
        rebateScore: { type: Number, default: 0 },
        spreaderID: { type: String, default: "" }
    }],
    detail: { type: String, default: "" },
    videoRecordID: { type: Number, default: 0 },
    createTime: { type: Number, default: 0 }
});
userGameRecordSchema.plugin(autoIncrement.plugin, {
    model: 'userGameRecord',
    field: 'index',
    startAt: 1000000,
    incrementBy: 1
});
db.model('userGameRecord', userGameRecordSchema);
exports.userGameRecordModel = db.model('userGameRecord');


// 玩家禁止同桌功能
let userBlockSchema = new Schema({

    unionID: { type: Number, default: 0 },
    creatorUid: { type: String, default: "" },
    userList: [{
        uid: { type: String, default: "" },
        nickname: { type: String, default: "" },
        avatar: { type: String, default: "" },
    }],
    createTime: { type: Number, default: 0 }
});
userBlockSchema.plugin(autoIncrement.plugin, {
    model: 'userBlock',
    field: 'ruleID',
    startAt: 100,
    incrementBy: 1
});
db.model('userBlock', userBlockSchema);
exports.userBlockModel = db.model('userBlock');


// 录像记录
let gameVideoRecordSchema = new Schema({
    roomID: { type: String, default: "" },
    gameType: { type: Number, default: 0 },
    detail: { type: String, default: "" },
    createTime: { type: Number, default: 0 }
});
gameVideoRecordSchema.plugin(autoIncrement.plugin, {
    model: 'gameVideoRecord',
    field: 'videoRecordID',
    startAt: 1000000,
    incrementBy: 1
});
db.model('gameVideoRecord', gameVideoRecordSchema);
exports.gameVideoRecordModel = db.model('gameVideoRecord');

// 玩家抽水记录
let userRebateRecordSchema = new Schema({
    uid: {
        type: String,
        default: ""
    }
});
db.model('userRebateRecord', userRebateRecordSchema);
exports.userRebateRecordModel = db.model('userRebateRecord');

// 短信验证码记录
let smsCodeRecordSchema = new Schema({
    phone: { type: String, default: "" },
    code: { type: String, default: "" },
    createTime: { type: Number, default: 0 }
});
db.model('smsCodeRecord', smsCodeRecordSchema);
exports.smsCodeRecordModel = db.model('smsCodeRecord');



//新的玩家分数变化记录
let userScoreDetailSchema = new Schema({
    uid: { type: String, default: "" }, // 玩家id
    nickname: { type: String, default: "" }, // 昵称
    unionID: { type: Number, default: 0 }, // 联盟ID
    changeCount: { type: Number, default: 0 }, // 分数变化
    leftCount: { type: Number, default: 0 }, // 剩余分数
    beforeCount: { type: Number, default: 0 }, // 剩余返利分数
    leftSaveBoxCount: { type: Number, default: 0 }, // 剩余保险柜分数
    changeType: { type: Number, default: 0 }, // 改变类型
    gameType: { type: Number, default: 0 }, // 游戏类型
    describe: { type: String, default: "" }, // 描述
    createTime: { type: String, default: 0 } // 操作时间
});
userScoreDetailSchema.index({ unionID: 1, changeType: 1, createTime: -1 });
db.model('userScoreDetail', userScoreDetailSchema);
exports.userScoreDetailModel = db.model('userScoreDetail');


// 联盟开房记录表
let unionGameRoomSchema = new Schema({
    ruleID: { type: String, default: "" }, //规则ID
    roomID: { type: Number, default: "" }, //房间ID
    unionID: { type: Number, default: 0 }, //联盟ID
    payDiamond: { type: Number, default: 0 }, //开房费用
    creatorInfo: { type: String, default: "" }, //创建信息
    createTime: { type: String, default: "" }, // 创建时间
    status: { type: Number, default: 0 } // 0 未完成 1 游戏中 2 已完成 
});
db.model('unionGameRoom', unionGameRoomSchema);
exports.unionGameRoom = db.model('unionGameRoom');


// 机器人设置相关
let robotSettingSchema = new Schema({
    unionID: { type: Number, default: 0 }, //联盟ID
});
db.model('robotSetting', robotSettingSchema);
exports.robotSetting = db.model('robotSetting');


// 留言板
let userNoteSchema = new Schema({

    uid: { type: String, default: "" }, //玩家ID
    nickname: { type: String, default: "" }, //玩家昵称
    message: { type: String, default: "" }, //信息
    contact: { type: String, default: "" }, //联系方式
    reply: { type: String, default: "" }, //回复
    createTime: { type: String, default: "" }, // 创建时间
    replyTime: { type: String, default: "" }, // 回复时间
    replyMessage: { type: String, default: "" }, // 回复消息
    status: { type: Number, default: 0 } // 0 未回复 1 已回复
});

db.model('userNote', userNoteSchema);
exports.userNoteModel = db.model('userNote');


// 刪除記錄
let useDelSchema = new Schema({

    unionID: { type: String, default: "" }, //联盟ID
    uid: { type: String, default: "" }, //玩家ID
    avatar: { type: String, default: "" }, //玩家頭像
    nickname: { type: String, default: "" }, //玩家昵称
    score: { type: Number, default: "" }, //分数
    doneUid: { type: String, default: "" }, //被刪除玩家
    doneAvatar: { type: String, default: "" }, //被刪除玩家頭像
    doneNickname: { type: String, default: "" }, //被刪除玩家昵称
    type: { type: Number, default: 0 }, //0 加入联盟 1 退出联盟  2:设为组长 3 取消组长 4 设为管理 5: 取消管理 6 修改组长
    createTime: { type: String, default: "" }, // 创建时间
});

db.model('userDel', useDelSchema);
exports.userDelModel = db.model('userDel');


// 刪除記錄
let gameLimitSchema = new Schema({

    unionID: { type: String, default: "" }, //联盟ID
    uid: { type: String, default: "" }, //玩家ID
    list: [],
    createTime: { type: String, default: "" }, // 创建时间
});

db.model('gameLimit', gameLimitSchema);
exports.gameLimitModel = db.model('gameLimit');


// 钻石記錄
let unionPaySchema = new Schema({

    unionID: { type: String, default: "" }, //联盟ID
    count: { type: Number, default: 0 }, //钻石数
    year: { type: Number, default: 0 }, //年
    month: { type: Number, default: 0 }, //月
    day: { type: String, default: "" }, //日期
    createTime: { type: Number, default: "" }, // 创建时间
});


db.model('unionPay', unionPaySchema);
exports.unionPayModel = db.model('unionPay');

// 钻石記錄
let userPaySchema = new Schema({

    unionID: { type: String, default: "" }, //联盟ID
    uid: { type: String, default: "" }, //玩家ID
    avatar: { type: String, default: "" }, //玩家頭像
    nickname: { type: String, default: "" }, //玩家昵称
    count: { type: Number, default: 0 }, //钻石数
    day: { type: String, default: "" }, //日期
    createTime: { type: Number, default: "" }, // 创建时间
});

db.model('userPay', userPaySchema);
exports.userPayModel = db.model('userPay');

// 钻石記錄
let userPayDetailSchema = new Schema({

    unionID: { type: String, default: "" }, //联盟ID
    roomID: { type: Number, default: 0 }, //房间号
    gameType: { type: Number, default: 0 }, //游戏类型
    uid: { type: String, default: "" }, //玩家ID
    avatar: { type: String, default: "" }, //玩家頭像
    nickname: { type: String, default: "" }, //玩家昵称
    count: { type: Number, default: 0 }, //钻石数
    day: { type: String, default: "" }, //日期
    createTime: { type: Number, default: "" }, // 创建时间
});

db.model('userPayDetail', userPayDetailSchema);
exports.userPayDetailModel = db.model('userPayDetail');

// 充值
let rechargeSchema = new Schema({
    gold: { type: Number, default: 0 }, // 砖石
    addGold: { type: Number, default: 0 }, // 赠送砖石
    count: { type: Number, default: 0 }, // 金额
    goodID: { type: String, default: "" }, //唯一ID
});
db.model('recharge', rechargeSchema);
exports.rechargeModel = db.model('recharge');

//订单
let orderSchema = new Schema({

    uid: { type: Number, default: 0 }, // 玩家ID
    gold: { type: Number, default: 0 }, // 砖石
    addGold: { type: Number, default: 0 }, // 赠送砖石
    count: { type: Number, default: 0 }, // 金额
    goodID: { type: String, default: 0 }, // 商品编码
    tradeNo: { type: String, default: "" }, // 支付商户订单号
    orderNo: { type: String, default: "" }, // 系统订单号
    payType: { type: String, default: "" }, // 支付方式
    type: { type: Number, default: 0 }, // 支付类型
    goodName: { type: String, default: "" }, // 商品名称
    createTime: { type: Number, default: 0 }, //创建时间
    endTime: { type: Number, default: 0 }, // 订单结束时间
    detail: {},
    status: { type: Number, default: 0 }, // 0 待支付  1:支付成功 -1：支付失败 -2：玩家取消

});
db.model('order', orderSchema);
exports.orderModel = db.model('order');

// 联盟游戏抽水记录表
let unionRoomRateSchema = new Schema({
    gameRuleID: { type: String, default: "" }, //规则ID
    unionID: { type: Number, default: 0 }, //联盟ID
    superUID: { type: Number, default: 0 }, //上级ID
    ownerUID: { type: Number, default: 0 }, //盟主ID
    uid: { type: Number, default: 0 }, //下级UID
    superRate: { type: Number, default: 0 }, //上级费用
    rate: { type: Number, default: 0 }, //固定费用
    rebateRate: { type: Number, default: 0 }, //抽水百分比
    fixRate: { type: Number, default: 0 }, //固定值百分比
    ticketRate: { type: Number, default: 0 }, //门票百分比
});

db.model('unionGameRate', unionRoomRateSchema);
exports.unionGameRateModel = db.model('unionGameRate');


//玩家目标
let userTargetSchema = new Schema({
    unionID: { type: Number, default: 1 },
    uid: { type: Number, default: 0 },
    score: { type: Number, default: 0 },
    maxBureau: { type: Number, default: 0 },
    curBureau: { type: Number, default: 0 },
    curDate: { type: Number, default: 0 },
    endScore: { type: Number, default: 0 },
    createTime: { type: String, default: "" },
    gameType: { type: Number, default: 0 },
    detail: [],
    endTime: { type: String, default: "" },
});

db.model('userTarget', userTargetSchema);
exports.userTargetModel = db.model('userTarget');


//玩家签到
let userSignSchema = new Schema({

    day: { type: Number, default: 0 }, // 星期
    gold: { type: Number, default: 0 }, // 砖石
    addGold: { type: Number, default: 0 }, // 额外砖石
    total: { type: Number, default: 0 },//总计
    uid: { type: String, default: "" }, //玩家ID
    avatar: { type: String, default: "" }, //玩家頭像
    nickname: { type: String, default: "" }, //玩家昵称
    signDay: { type: Number, default: 0 }, // 日期
    createTime: { type: Number, default: 0 }, //创建时间
});
db.model('userSign', userSignSchema);
exports.userSignModel = db.model('userSign');


//签到
let signGoldSchema = new Schema({
    day: { type: Number, default: 0 }, // 星期
    gold: { type: Number, default: 0 }, // 砖石
    addGold: { type: Number, default: 0 }, // 赠送砖石

});
db.model('signGold', signGoldSchema);
exports.signGoldModel = db.model('signGold');


// 转盘
let giftSchema = new Schema({

    type: { type: Number, default: 0 }, //0 金币  1 钻石
    count: { type: Number, default: 0 }, // 数量
    order: { type: Number, default: 0 }, // 序号
    percent: { type: Number, default: 0 }, // 概率
    icon: { type: Number, default: 0 }, // 图标

});
db.model('gift', giftSchema);
exports.giftModel = db.model('gift');


// 奖励
let rewardSchema = new Schema({

    type: { type: Number, default: 0 }, //0 金币  1 钻石
    count: { type: Number, default: 0 }, // 数量
    day: { type: Number, default: 0 }, // 序号
    icon: { type: Number, default: 0 }, // 图标

});
db.model('reward', rewardSchema);
exports.rewardModel = db.model('reward');


//玩家签到
let userPlaySchema = new Schema({

    dayTime: { type: Number, default: 0 }, // 年-月
    count: { type: Number, default: 0 }, // 连续次数
    uid: { type: String, default: "" }, //玩家ID
    avatar: { type: String, default: "" }, //玩家頭像
    nickname: { type: String, default: "" }, //玩家昵称
    playDay: { type: Number, default: 0 }, // 上次玩的日期
    playTime: { type: Number, default: 0 }, // 今天玩的次数
    createTime: { type: Number, default: 0 }, //创建时间
});
db.model('userPlay', userPlaySchema);
exports.userPlayModel = db.model('userPlay');



// 奖励
let userRewardSchema = new Schema({
    uid: { type: Number, default: 0 }, // 玩家iD
    dayTime: { type: Number, default: 0 }, // 年-月
    type: { type: Number, default: 0 }, //0 金币  1 钻石
    count: { type: Number, default: 0 }, // 数量
    day: { type: Number, default: 0 }, // 天数
    done: { type: Boolean, default: false }, // 天数
});

db.model('userReward', userRewardSchema);
exports.userRewardModel = db.model('userReward');
